 /* eslint-disable */
<template>
    <div class="total">
      <div
        class="tot_num"
        :class="{'number-item': !isNaN(item), 'mark-item': isNaN(item) }"
        v-for="(item,index) in orderNum"
        :key="index"
      >
        <span v-if="!isNaN(item)">
          <i ref="numberItem">0123456789</i>
        </span>
        <span class="comma" v-else>{{item}}</span>
      </div>
    </div>
</template>
<script>
/* eslint-disable */
export default {
  data() {
    return {
      orderNum: ["0", "0", "0", "0", "0", "0", "0", "0", "0"] // 默认订单总数
      //    pointD: this.$store.modules.stateM.point
    };
  },
  props:["num"],
  watch: {
    num(newName, oldName) {
      setTimeout(() => {
        this.toOrderNum(newName);
        // console.log(newName)
      }, 500);
    }
  },
  mounted() {
    setTimeout(() => {
      this.toOrderNum(this.num);
    //   console.log(this.num)
    }, 500);
    // console.log(this.$store.state.stateM.point[0].point_num);
  },
  methods: {
    // 设置文字滚动
    setNumberTransform() {
      const numberItems = this.$refs.numberItem; // 拿到数字的ref，计算元素数量
      const numberArr = this.orderNum.filter(item => !isNaN(item));
    //   const numberArr = this.orderNum;
    //    console.log(numberArr)
      // 结合CSS 对数字字符进行滚动,显示订单数量
      for (let index = 0; index < numberItems.length; index++) {
        const elem = numberItems[index];
        // console.log(elem)
        elem.style.transform = `translate(-50%, -${numberArr[index] * 10}%)`;
      }
    },
    // 处理总订单数字
    toOrderNum(num) {
      num = num.toString();
      // 把订单数变成字符串
      if (num.length < 9) {
        num = " " + num; // 如未满八位数，添加"0"补位
        this.toOrderNum(num); // 递归添加"0"补位
      } else if (num.length === 9) {
        // 订单数中加入逗号
        // num = num.slice(0, 2) + ',' + num.slice(2, 5) + ',' + num.slice(5, 8)
        this.orderNum = num.split(""); // 将其便变成数据，渲染至滚动数组
        // console.log(this.orderNum )
      } else {
        // 订单总量数字超过八位显示异常
        this.$message.warning("总量数字过大");
      }
      this.setNumberTransform();
    }
  }
};
</script>
<style scoped lang="scss">
/* 默认逗号设置 */
.mark-item {
  width: 10px;
  height: 100px;
  margin-right: 5px;
  line-height: 10px;
  font-size: 48px;
  position: relative;
  & > span {
    position: absolute;
    width: 100%;
    bottom: 0;
    writing-mode: vertical-rl;
    text-orientation: upright;
  }
}
/*滚动数字设置*/
.number-item {
  width: 41px;
  height: 75px;
  /* 背景图片 */
//   background: chartreuse;

  list-style: none;
  margin-right: 5px;
 
  & > span {
    position: relative;
    display: inline-block;
    margin-right: 10px;
    width: 100%;
    height: 100%;
    writing-mode: vertical-rl;
    text-orientation: upright;
    overflow: hidden;
    & > i {
      font-style: normal;
      position: absolute;
      top:7px;
      left: 50%;
      transform: translate(-50%, 0);
      transition: transform 1s ease-in-out;
      letter-spacing: 10px;
    }
  }
}
.number-item:last-child {
  margin-right: 0;
}
.tot_title,
.tot_num {
  float: left;
  color: #29b5e8;
  font-size: 25px;
  width: 66px;
//   height: 50px;
//   line-height: 50px;
  margin-right: 15px;
  margin-left: 20px;
}
.tot_num {
  width: 15px;
  height: 40px;
  margin-top: 5px;
  line-height: 40px;
 
  color: #000;
  margin-right: 0px;
  margin-left: 0px;
}
.total {
//   width: 261px;
//   height: 50px;
  background: none;
display: block;
}
</style>